<?php
/**
 * Controller for actions (in admin area) of member module
 *  
 * @version 2012-10-10
 * @package member
 * @subpackage controller
 * @category Member_Controller_Admin
 */
class Mail_Controller_Admin extends Controller
{
	/**
	 * Default action
	 *
	 * @version 2012-10-10
	 * @param Request $req
	 * @return View
     * @access public 
	 */	
	public function processIndex($req)
	{
		return $this->processMembers($req);
	}

	/**
	 * MonitoringMember
	 * This function shows the list of persons.
	 * This function forms a query to the database with the help of a block of filters and returns an object VIEW that contains the array 'members' with data
	 * 
	 * @version 2012-10-24
	 * @param Request $req
	 * @return View
    * @access public 
	 */
	public function processMembers($req) {
		// Here local values are declared 
		$view = $this->getView("admin_member");
		//$dbMembers = Db::getModel('members');
		m('email_templates');
		
		/*		
		$url    = new Url();
		$url2 = new Url();
		$pager = new Pager($url,30);
		$sorter = new Sorter($url);		
		$sorterCfg = array(
			'cdate',
			'name',
			'email',
			'phone',
			'cnt_complaints',
			'cnt_comments',
			'status'
        );
		  
		  // Here filter conditions are set up
        $filterCfg= array(
            'name' => 'like',
            'search' => 'like',
            'phone' => "like",
            'status' => "=",
			'email'=> "like",
            'cdate' => 'date_range',
        );
		$filter = new Filter('monitoring_member', $filterCfg);
		
		$filter->process($req);
		$sorter->init($sorterCfg);
		$sort   = array($sorter->getOrder());
		$where = $filter->getCriteria();
		$view->setVar('fltInfo',$filter->getInfo());
		$members = $dbMembers->getMembersList(array_merge(array("utype"=>"='member'","status"=>"NOT IN ('deleted')"),$where),$pager,$sort);
		$view->setVar("members",$members);
		$view->setVar('pagerInfo',$pager->getInfo());
			if($req->getInt('page'))
				$url2->setParam('page',$req->getInt('page'));
			if($req->get('filter_monitoring_member')== 'on')
				$url2->setParam('filter_monitoring_member',"on");
		$url2->setParam('act',"member_action");
		$view->setVar('currentUrl',$url2->getUrl());
		$view->setVar('srtInfo', $sorter->getInfo());
		$view->setVar('person_autocomplete',_strJSON($dbMembers->getHash('CONCAT(fname," ",lname)',array('status'=>'NOT IN("deleted")','utype'=>"='member'"))),0);
		$view->setVar('email_autocomplete',_strJSON($dbMembers->getHash('email',array('status'=>'NOT IN("deleted")','utype'=>"='member'"))),0);
		$view->setVar('phone_autocomplete',_strJSON($dbMembers->getHash('phone',array('status'=>'NOT IN("deleted")','utype'=>"='member'"))),0);
			
		*/
		return $view;
	}
}